#include <iostream>

#include <gtest/gtest.h>

#include "melon/client/thrift_client_pool.h"
#include "cloud_control/adapters/cloud_control_privilege_adapter.h"

#include "CloudControlPrivilegeService.h"
#include "CloudControlPrivilegeService_types.h"
#include "CloudControlServiceCommon_types.h"


using namespace cc;
using cc::CloudControlPrivilegeServiceClient;
using melon::client::ClientPool;

void * ThreadFun(void *) {
  for (int i = 0; i < 2; ++i) {
    std::string phone = "13520636947";
    std::string pc_mid1 = "1234567890ABCDEF";
    std::string pc_mid2 = "FEDCBA0987654321";
    std::string pc_mid3 = "FEDCBA0987654321-no";
    int64_t pc_qid = 1234567890;
    std::string code = "123456789";

    int64_t ret = CloudControlPrivilegeAdapter::Instance().HasPrivilege(phone, pc_qid, pc_mid1, 2);
    cout << "ret=" << ret << std::endl;
    ret = CloudControlPrivilegeAdapter::Instance().HasPrivilege(phone, pc_qid, pc_mid2, 2);
    cout << "ret=" << ret << std::endl;

    CloudControlPrivilegeAdapter::Instance().ApplyPrivilege(phone, phone, pc_qid, pc_mid1, code, 2);
    CloudControlPrivilegeAdapter::Instance().ApplyPrivilege(phone, phone, pc_qid, pc_mid2, code, 2);

    ret = CloudControlPrivilegeAdapter::Instance().AcceptPrivilege(phone, pc_qid, pc_mid1, code, 2);
    cout << "ret=" << ret << std::endl;
    ret = CloudControlPrivilegeAdapter::Instance().AcceptPrivilege(phone, pc_qid, pc_mid2, code, 2);
    cout << "ret=" << ret << std::endl;
    ret = CloudControlPrivilegeAdapter::Instance().AcceptPrivilege(phone, pc_qid, pc_mid3, code, 2);
    cout << "ret=" << ret << std::endl;
  }
  return NULL;
}

const int kThreadCount = 1;

int main() {
  LOG_INIT("./test.log", "DEBUG");
  pthread_t ts[kThreadCount];

  for (int i = 0; i < kThreadCount; ++i) {
    pthread_create(&ts[i], NULL, ThreadFun, NULL);
  }

  for (int i = 0; i < kThreadCount; ++i) {
    pthread_join(ts[i], NULL);
  }
  return 0;
}


